<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="对应条码(S)">
              <a-input placeholder="请输入对应条码(S)" v-model="queryParam.correspondingBarcode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户编码">
              <a-input placeholder="请输入客户编码" v-model="queryParam.customerCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="集研编码">
              <a-input placeholder="请输入集研编码" v-model="queryParam.researchCode"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="测试工位">
                <j-dict-select-tag placeholder="请选择测试工位" v-model="queryParam.testStation" dictCode="test_station"/>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="发生日期">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.happenDate_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.happenDate_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="测试人员">
                <a-input placeholder="请输入测试人员" v-model="queryParam.firstTestPersonnel"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="维修人员">
                <a-input placeholder="请输入维修人员" v-model="queryParam.repairPersonnel"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="测试人员">
                <a-input placeholder="请输入测试人员" v-model="queryParam.retestPersonnel"></a-input>
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="确认人员">
                <a-input placeholder="请输入确认人员" v-model="queryParam.confirmationPersonnel"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="unqualified_repair_card"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="制令单号">
                <a-input placeholder="请输入制令单号" v-model="queryParam.commandbillCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="生产订单ID">
                <a-input placeholder="请输入生产订单ID" v-model="queryParam.produceId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="类型">
                <j-dict-select-tag placeholder="请选择类型" v-model="queryParam.type" dictCode="repair_type"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="线别">
                <!--<j-dict-select-tag placeholder="请选择线别" v-model="queryParam.lineType" dictCode="mgroup_code"/>-->
                <a-input placeholder="请输入线别" v-model="queryParam.lineType"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="机型">
                <a-input placeholder="请输入机型" v-model="queryParam.model"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchin" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('宗申测试不合格反修卡')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="repairtype === 'repair_zs' ? columns : columnszyz"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                   <a @click="repairModal(record)">维修完成</a>
              </a-menu-item>
              <a-menu-item>
                  <a @click="handleConfirm(record.id)">确认完成</a>
              </a-menu-item>
               <a-menu-item v-if="repairtype === 'repair_zs'">
                <span @click="showPrint(record)">打印</span>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <zsUnqualifiedRepairCard-modal ref="modalForm" @ok="modalFormOk"></zsUnqualifiedRepairCard-modal>
    <a-modal v-model="visibleDetail" title="测试不合格及返修卡" @ok="handleOk" width="50%" :footer="null">
      <zsUnquali :reportData="reportData"/>
    </a-modal>
    <a-modal v-model="visibleRepair" title="维修完成" width="50%" :footer="null">
      <a-form
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
      >
        <a-form-item label="不合格原因">
          <a-input v-model:value="formState.unqualifiedReason" placeholder="请输入不合格原因"/>
        </a-form-item>
        <a-form-item label="维修方案">
          <a-input v-model:value="formState.repairProgramme" placeholder="请输入维修方案"/>
        </a-form-item>
        <a-form-item label="维修人员">
          <a-input v-model:value="formState.repairPersonnel" placeholder="请输入维修人员"/>
        </a-form-item>
        <a-form-item :wrapper-col="{ span: 14, offset: 10 }">
          <a-button type="primary" @click="onSubmit">确定</a-button>
          <a-button style="margin-left: 10px" @click="visibleRepair = false">取消</a-button>
        </a-form-item>
      </a-form>
    </a-modal>
    <a-modal v-model="repairConfirm" title="维修完成" width="50%" :footer="null">
      <a-form
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
      >
        <a-form-item label="测试人员">
          <a-input v-model:value="confirmForm.retestPersonnel" placeholder="请输入测试人员"/>
        </a-form-item>
        <a-form-item label="确认人员">
          <a-input v-model:value="confirmForm.confirmationPersonnel" placeholder="请输入确认人员"/>
        </a-form-item>
        <a-form-item :wrapper-col="{ span: 14, offset: 10 }">
          <a-button type="primary" @click="onConfirm">确定</a-button>
          <a-button style="margin-left: 10px" @click="repairConfirm = false">取消</a-button>
        </a-form-item>
      </a-form>
    </a-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ZsUnqualifiedRepairCardModal from './modules/ZsUnqualifiedRepairCardModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import zsUnquali from '@/views/inspect/zsUnquali'

  export default {
    name: "ZsUnqualifiedRepairCardList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      JDate,
      zsUnquali,
      ZsUnqualifiedRepairCardModal,

    },
    data () {
      return {
        description: '宗申测试不合格反修卡管理页面',
        formState:{
          unqualifiedReason:'',
          repairProgramme:'',
          repairPersonnel:'',
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        visibleRepair:false,
        repairConfirm:false,
        visibleDetail:false,
        reportData:[],
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'客户编码',
            align:"center",
            dataIndex: 'customerCode'
          },
          {
            title:'集研编码',
            align:"center",
            dataIndex: 'researchCode'
          },
          {
            title:'测试工位',
            align:"center",
            dataIndex: 'testStation_dictText'
          },
          {
            title:'发生日期',
            align:"center",
            dataIndex: 'happenDate'
          },
          {
            title:'不合格现象',
            align:"center",
            dataIndex: 'unqualifiedPhenomenon'
          },
          {
            title:'测试人员',
            align:"center",
            dataIndex: 'firstTestPersonnel'
          },
          {
            title:'不合格原因',
            align:"center",
            dataIndex: 'unqualifiedReason'
          },
          {
            title:'维修方案',
            align:"center",
            dataIndex: 'repairProgramme'
          },
          {
            title:'维修人员',
            align:"center",
            dataIndex: 'repairPersonnel'
          },
          {
            title:'维修完成后在测试结果',
            align:"center",
            dataIndex: 'retestResults'
          },
          {
            title:'测试人员',
            align:"center",
            dataIndex: 'retestPersonnel'
          },
          {
            title:'对应条码(S)',
            align:"center",
            dataIndex: 'correspondingBarcode'
          },
          {
            title:'确认人员',
            align:"center",
            dataIndex: 'confirmationPersonnel'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'制令单号',
            align:"center",
            dataIndex: 'commandbillCode'
          },
          {
            title:'生产订单ID',
            align:"center",
            dataIndex: 'produceId'
          },
          // {
          //   title:'类型',
          //   align:"center",
          //   dataIndex: 'type_dictText'
          // },
          // {
          //   title:'班别',
          //   align:"center",
          //   dataIndex: 'classType'
          // },
          // {
          //   title:'线别',
          //   align:"center",
          //   dataIndex: 'lineType_dictText'
          // },
          // {
          //   title:'站别',
          //   align:"center",
          //   dataIndex: 'standType'
          // },
          // {
          //   title:'机型',
          //   align:"center",
          //   dataIndex: 'model'
          // },
          // {
          //   title:'不良数量',
          //   align:"center",
          //   dataIndex: 'badQuantity'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            // fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        columnszyz:[
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'制令单号',
            align:"center",
            dataIndex: 'commandbillCode'
          },
          {
            title:'生产订单ID',
            align:"center",
            dataIndex: 'produceId'
          },
          {
            title:'班别',
            align:"center",
            dataIndex: 'classType'
          },
          {
            title:'线别',
            align:"center",
            dataIndex: 'lineType'
          },
          {
            title:'站别',
            align:"center",
            dataIndex: 'standType'
          },
          {
            title:'机型',
            align:"center",
            dataIndex: 'model'
          },
          {
            title:'不良数量',
            align:"center",
            dataIndex: 'badQuantity'
          },
          {
            title:'日期',
            align:"center",
            dataIndex: 'happenDate'
          },
          {
            title:'SN',
            align:"center",
            dataIndex: 'correspondingBarcode'
          },
          {
            title:'不良现象',
            align:"center",
            dataIndex: 'unqualifiedReason'
          },
          {
            title:'维修位置',
            align:"center",
            dataIndex: 'repairProgramme'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            // fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/inspect/zsUnqualifiedRepairCard/list",
          delete: "/inspect/zsUnqualifiedRepairCard/delete",
          deleteBatch: "/inspect/zsUnqualifiedRepairCard/deleteBatch",
          exportXlsUrl: "/inspect/zsUnqualifiedRepairCard/exportXls",
          importExcelUrl: "inspect/zsUnqualifiedRepairCard/importExcel",
        },
        dictOptions:{},
        repairtype:'repair_yzy',
        confirmForm:{
          status:'confirm_complete',
          id:'',
          retestPersonnel:'',
          confirmationPersonnel:''
        }
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleConfirm(id){
        this.confirmForm.id = item.id
        this.confirmForm.retestPersonnel = ''
        this.confirmForm.confirmationPersonnel = ''
        this.repairConfirm = true
      },
      onConfirm(){
        if (!this.confirmForm.retestPersonnel){
          return this.$message.error('请输入测试人员!')
        }
        if (!this.confirmForm.confirmationPersonnel){
          return this.$message.error('请输入确认人员!')
        }
        this.$http.post('inspect/zsUnqualifiedRepairCard/edit', this.confirmForm).then(res => {
          if (res.success) {
            this.$message.success('操作成功!')
            this.repairConfirm = false
            this.loadData();
          } else {
            this.$message.error(res.message)
          }
        })
      },
      repairModal(item){
        this.formState.id = item.id
        this.formState.status = 'waiting_retest'
        this.formState.unqualifiedReason = ''
        this.formState.repairProgramme = ''
        this.formState.repairPersonnel = ''
        this.visibleRepair = true
      },
      onSubmit(){
        if (!this.formState.unqualifiedReason){
          return this.$message.error('请输入不合格原因!')
        }
        if (!this.formState.repairProgramme){
          return this.$message.error('请输入维修方案!')
        }
        if (!this.formState.repairPersonnel){
          return this.$message.error('请输入维修人员!')
        }
        this.$http.post('inspect/zsUnqualifiedRepairCard/edit', this.formState).then(res => {
          if (res.success) {
            this.$message.success('操作成功!')
            this.visibleRepair = false
            this.loadData();
          } else {
            this.$message.error(res.message)
          }
        })
      },
      searchin(){
        this.repairtype = this.queryParam.type
        this.loadData(1);
      },
      initDictConfig(){
      },
      showPrint(row){
        console.log(11,row)
        this.reportData = row
        this.visibleDetail = true
      },
      handleOk(e) {
        this.visibleDetail = false;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>